package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishMapper {
    List<Dish> selectAllByPage(String name);

    Integer update(Dish dish);

    @Select("select * from dish where id=#{id}")
    Dish selectById(Long id);

    //根据id判断是否可以删除
    @Select("select count(*) from dish where category_id=#{categoryId}")
    Integer selectCountByCategoryId(Long categoryId);

    //多选删除
    Integer deleteByIds(@Param("ids") Long[] ids);

    //批量启售 停售
    Integer updateStatus(@Param("status") Integer status,@Param("ids") Long[] ids);
    //添加菜品
    @Insert("INSERT INTO dish VALUES (NULL,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},0,#{createTime},#{updateTime},#{createUser},#{createUser},0)")
    @Options(useGeneratedKeys = true,keyColumn ="id",keyProperty ="id")
    Integer add(DishDto dishDto);

    //通过categoryId查找菜品
    @Select("select * from dish where category_id=#{categoryId}")
    List<Dish> findByCategoryId(Long categoryId);

    //通过categoryId查找菜品与口味,返回DishDto
    @Select("select * from dish where category_id=#{categoryId} and status=#{status}")
    List<Dish> findByCategoryIdAndStatus(@Param("categoryId") Long categoryId,@Param("status")Integer status);


}
